<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>纯CSS实现无缝滚动的弹幕效果~一个视频学会CSS实现无缝滚动的原理</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Poppins', sans-serif;
            user-select: none;
        }
        body {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background-color: #111;
        }
        .container {
            position: relative;
            display: flex;
            width: 700px;
            overflow: hidden;
            /* 目的是将左右两边的部分虚化隐藏 */
            mask-image: linear-gradient(
                90deg,
                transparent, #fff 20%,
                #fff 80%, transparent
            );
        }
        .container div {
            white-space: nowrap;
            animation: animate1 var(--t) linear infinite;
        }
        .container div:nth-child(2) {
            animation: animate2 var(--t) linear infinite;
            animation-delay: calc(var(--t) / -2);
        }
        @keyframes animate1 {
            from {
                transform: translate(100%);
            }
            to {
                transform: translate(-100%);
            }
        }
        @keyframes animate2 {
            from {
                transform: translate(0);
            }
            to {
                transform: translate(-200%);
            }
        }
        .container div span {
            display: inline-flex;
            margin: 10px;
            letter-spacing: .2em;
            background-color: #333;
            color: #fff;
            padding: 5px 10px;
            border-radius: 5px;
        }
    </style>
</head>
<body>
    <script>
        let s = "";
        let arr = ['40s', '30s', '50s', '20s'];
        arr.forEach((t) => {
            s += `<div class="container" style="--t:${t}">`;
            s += `<div><span>HTML</span><span>CSS</span><span>JAVASCRIPT</span><span>PHP</span><span>JAVA</span><span>VUE</span><span>THREEJS</span></div>`;
            s += `<div><span>HTML</span><span>CSS</span><span>JAVASCRIPT</span><span>PHP</span><span>JAVA</span><span>VUE</span><span>THREEJS</span></div>`;
            s += `</div>`;
        });
        document.body.innerHTML = s;
    </script>
</body>
</html>
